package cn.innosmart.aq.manager;

import com.tutk.p2p.ConnectionEntity;
import com.tutk.p2p.ResponseHandler;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;

import cn.innosmart.aq.bean.AquariumBean;
import cn.innosmart.aq.util.SystemConstant;

/**
 * Created by David on 2015/7/1.
 */
public class SystemManager extends BaseManager {
    private static GetInfoCallBack getInfoCallBack;
    private static QueryStorageInfoCallBack queryStorageInfoCallBack;
    private static QueryFlashInfoCallBack queryFlashInfoCallBack;
    private static ResetCallBack resetCallBack;
    private static DownloadCallBack downloadCallBack;
    private static ConfirmCallBack confirmCallBack;
    private static GetTimeZone getTimeZoneCallBack;
    private static SetTimeZone setTimeZoneCallBack;
    private String Tag = "SystemManager";
    private ResponseHandler.ResponseCallback mSystemManagerUpdateFirmwareCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.UpdateFirmware get response=" + message);

        }
    };
    private ResponseHandler.ResponseCallback mSystemManagerConfirmUpgradeCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.ConfirmUpgrade get response=" + message);

        }
    };
    /**
     * {"code":0,"message":"Success","result":{"name":"Palals","firmware_version":"V15.08.31",
     * "system_timestamp":1441073499,"timezone_offset":0},"type":"resp","callid":1441073498539,"method":"SystemManager.GetInfo"}
     */
    private ResponseHandler.ResponseCallback mSystemManagerGetInfoCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.GetInfo get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    String versionName = jRoot.getJSONObject("result").getString("firmware_version");
                    if (getInfoCallBack != null) {
                        getInfoCallBack.onGetInfoResponseCallBack(0, versionName);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    private ResponseHandler.ResponseCallback mSystemManagerUpdateCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.Update get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    /**
     * {"code":0,"message":"Success","result":{"output":{"Filesystem":"/dev/mtdblock5","Total":"12224","Used":"2944",
     * "Available":"9280","UsePercent":"24%"}},"type":"resp","callid":1441074396046,"method":"SystemManager.CmdDf"}
     */

    private ResponseHandler.ResponseCallback mSystemManagerQueryStorageInfoCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.CmdDf get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    JSONObject jsonObject = jRoot.getJSONObject("result").getJSONObject("output");
                    ;
                    if (queryStorageInfoCallBack != null) {
                        queryStorageInfoCallBack.onQueryStorageInfoResponseCallBack(0, jsonObject);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    /**
     * {"code":0,"message":"Success","result":{"output":{"total":"59520","used":"24836","free":"34684","shared":"0"}},
     * "type":"resp","callid":1441074395199,"method":"SystemManager.CmdFree"}
     */
    private ResponseHandler.ResponseCallback mSystemManagerQueryFlashInfoCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.CmdDf get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    JSONObject jsonObject = jRoot.getJSONObject("result").getJSONObject("output");
                    if (queryFlashInfoCallBack != null) {
                        queryFlashInfoCallBack.onQueryFlashInfoResponseCallBack(0, jsonObject);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    /**
     * {"code":0,"message":"Success","result":{"output":{"total":"59520","used":"24836","free":"34684","shared":"0"}},
     * "type":"resp","callid":1441074395199,"method":"SystemManager.CmdFree"}
     */
    private ResponseHandler.ResponseCallback mSystemManagerResetCallBack = new ResponseHandler.ResponseCallback() {

        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.Reset get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    if (resetCallBack != null) {
                        resetCallBack.onResetCallBack(0, jRoot);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    /**
     * {"code":0,"message":"Success","result":{"output":{"total":"59520","used":"24836","free":"34684","shared":"0"}},
     * "type":"resp","callid":1441074395199,"method":"SystemManager.CmdFree"}
     */
    private ResponseHandler.ResponseCallback mSystemManagerDownloadFirmwareCallBack = new ResponseHandler.ResponseCallback() {

        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.DownloadFirmware get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    if (downloadCallBack != null) {
                        downloadCallBack.onDownloadCallBack(0);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    private ResponseHandler.ResponseCallback mSystemManagerConfirmUpgradeFirmwareCallBack = new ResponseHandler.ResponseCallback() {

        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.ConfirmUpgradeFirmware get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    if (confirmCallBack != null) {
                        confirmCallBack.onConfirmCallBack(0);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    private ResponseHandler.ResponseCallback mSystemManagerGetTimeZoneCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.GetTimeZone get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    if (getTimeZoneCallBack != null) {
                        getTimeZoneCallBack.onGetTimeZoneCallBack(jRoot.getString("result"));
                    }
                } else {
                    if (getTimeZoneCallBack != null) {
                        getTimeZoneCallBack.onGetTimeZoneCallBack(null);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                if (getTimeZoneCallBack != null) {
                    getTimeZoneCallBack.onGetTimeZoneCallBack(null);
                }
            }
        }
    };
    private ResponseHandler.ResponseCallback mSystemManagerSetTimeZoneCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.SetTimeZone get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    if (setTimeZoneCallBack != null) {
                        setTimeZoneCallBack.onSetTimeZoneCallBack(jRoot.getString("result"));
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };
    private ModifyPassword onModifyPassword;
    private ResponseHandler.ResponseCallback mSystemManagerUpdateUserCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.UpdateUser get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    if (onModifyPassword != null) {
                        onModifyPassword.onModifyPasswordCallBack(0);
                    }
                } else {
                    if (onModifyPassword != null) {
                        onModifyPassword.onModifyPasswordCallBack(-1);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                if (onModifyPassword != null) {
                    onModifyPassword.onModifyPasswordCallBack(-1);
                }
            }
        }
    };
    private onReboot onRebootCallBack;
    private ResponseHandler.ResponseCallback mSystemManagerExecuteShellScriptCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.ExecuteShellScript get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    if (onRebootCallBack != null)
                        onRebootCallBack.onRebootCallBack(0);
                } else {
                    if (onRebootCallBack != null)
                        onRebootCallBack.onRebootCallBack(-1);
                }
            } catch (Exception e) {
                e.printStackTrace();
                if (onRebootCallBack != null)
                    onRebootCallBack.onRebootCallBack(-1);
            }
        }
    };

    private SystemManager() {
    }

    public static SystemManager getInstance() {
        return SystemManagerInstance.instance;
    }

    // SystemManager.UpdateFirmware
    public boolean UpdateFirmware(ConnectionEntity connectionEntity, HashMap<Long, ResponseHandler> mReqRspHashMap, String UID, String params, long callid) {
        log(Tag, "UpdateFirmware. UID = " + UID + ", params = " + params);
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerUpdateFirmwareCallBack);
        mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, UID, "SystemManager.UpdateFirmware", params, callid)) {
            mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    // SystemManager.ConfirmUpgrade
    public boolean ConfirmUpgrade(ConnectionEntity connectionEntity, HashMap<Long, ResponseHandler> mReqRspHashMap, String UID, String params, long callid) {
        log(Tag, "ConfirmUpgrade. UID = " + UID + ", params = " + params);
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerConfirmUpgradeCallBack);
        mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, UID, "SystemManager.ConfirmUpgradeFirmware", params, callid)) {
            mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    // SystemManager.GetInfo
    public boolean GetInfo(ConnectionEntity connectionEntity, GetInfoCallBack getInfoCallBack) {
        this.getInfoCallBack = getInfoCallBack;
        log(Tag, "GetInfo. UID = " + connectionEntity.getUid());
        long callid = System.currentTimeMillis();
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerGetInfoCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.GetInfo", "{}", callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    // SystemManager.Update
    public boolean Update(ConnectionEntity connectionEntity, String params, ModifyPassword onModifyPassword) {
        this.onModifyPassword = onModifyPassword;
        log(Tag, "Update. UID = " + connectionEntity.getUid() + ", params = " + params);
        ResponseHandler handler = new ResponseHandler();
        long callid = System.currentTimeMillis();
        handler.setCallback(mSystemManagerUpdateCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.Update", params, callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    // SystemManager.Update
    public boolean UpdateUser(ConnectionEntity connectionEntity, String params, ModifyPassword onModifyPassword) {
        this.onModifyPassword = onModifyPassword;
        log(Tag, "UpdateUser. UID = " + connectionEntity.getUid() + ", params = " + params);
        ResponseHandler handler = new ResponseHandler();
        long callid = System.currentTimeMillis();
        handler.setCallback(mSystemManagerUpdateUserCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.UpdateUser", params, callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    // SystemManager.ExecuteShellScript
    public boolean ExecuteShellScript(ConnectionEntity connectionEntity, String params, onReboot onRebootCallBack) {
        this.onRebootCallBack = onRebootCallBack;
        log(Tag, "ExecuteShellScript. UID = " + connectionEntity.getUid() + ", params = " + params);
        long callid = System.currentTimeMillis();
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerExecuteShellScriptCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.ExecuteShellScript", params, callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    public boolean QueryStorageInfo(ConnectionEntity connectionEntity, QueryStorageInfoCallBack queryStorageInfoCallBack) {
        this.queryStorageInfoCallBack = queryStorageInfoCallBack;
        log(Tag, "CmdDf. UID = " + connectionEntity.getUid());
        long callid = System.currentTimeMillis();
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerQueryStorageInfoCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.CmdDf", new JSONObject().toString(), callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    public boolean QueryFlashInfo(ConnectionEntity connectionEntity, QueryFlashInfoCallBack queryFlashInfoCallBack) {
        this.queryFlashInfoCallBack = queryFlashInfoCallBack;
        log(Tag, "CmdDf. UID = " + connectionEntity.getUid());
        long callid = System.currentTimeMillis();
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerQueryFlashInfoCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.CmdFree", new JSONObject().toString(), callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    private ResponseHandler.ResponseCallback mGetUserDataCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.GetUserdata get response=" + message);
            JSONObject jRoot = null;
            try {
                jRoot = new JSONObject(message);
                int rspCode = jRoot.getInt("code");
                String rspMsg = jRoot.getString("message");
                if (0 == rspCode && "Success".equals(rspMsg)) {
                    JSONObject result = jRoot.getJSONObject("result");
                    JSONObject userdata = result.getJSONObject("userdata");
                    SystemConstant.heart_enable = userdata.getInt("heart_enable");
                    SystemConstant.heart_pns_priority = userdata.getInt("heart_pns_priority");
                } else {
                    log(Tag, "SystemManager.GetUserdata fail: " + rspMsg);
                }
            } catch (Exception e) {
                SystemConstant.heart_enable = 0;
                SystemConstant.heart_pns_priority = 4; //normal
            }
        }
    };

    public boolean GetUserData(ConnectionEntity connectionEntity, int delay) {
        log(Tag, "GetUserData. UID = " + connectionEntity.getUid());
        connectionEntity.flags.add(connectionEntity.SYSTEMMANAGER_GETDATA);
        long callid = System.currentTimeMillis() / 1000;
        if (delay != 0) {
            callid = callid + delay;
        }
        JSONObject jParams = new JSONObject();
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mGetUserDataCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.GetUserdata", jParams.toString(), callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    private ResponseHandler.ResponseCallback mSetUserDataCallBack = new ResponseHandler.ResponseCallback() {
        @Override
        public void onResponseCallback(ConnectionEntity connectionEntity, String message) {
            log(Tag, "SystemManager.SetUserdata get response=" + message);
        }
    };

    public boolean SetUserData(ConnectionEntity connectionEntity, JSONObject jParams, int delay) {
        log(Tag, "SetUserData. UID = " + connectionEntity.getUid());
        connectionEntity.flags.add(connectionEntity.SYSTEMMANAGER_SETDATA);
        long callid = System.currentTimeMillis() / 1000;
        if (delay != 0) {
            callid = callid + delay;
        }
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSetUserDataCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.SetUserdata", jParams.toString(), callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    public boolean Reset(ConnectionEntity connectionEntity, ResetCallBack resetCallBack) {
        this.resetCallBack = resetCallBack;
        log(Tag, "Reset. UID = " + connectionEntity.getUid());
        long callid = System.currentTimeMillis();
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerResetCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "ZWaveController.Reset", new JSONObject().toString(), callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    public boolean DownloadFirmware(ConnectionEntity connectionEntity, String params, DownloadCallBack downloadCallBack) {
        this.downloadCallBack = downloadCallBack;
        log(Tag, "DownloadFirmware. UID = " + connectionEntity.getUid());
        long callid = System.currentTimeMillis();
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerDownloadFirmwareCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.DownloadFirmware", params, callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    public boolean ConfirmUpgradeFirmware(ConnectionEntity connectionEntity, String params, ConfirmCallBack confirmCallBack) {
        this.confirmCallBack = confirmCallBack;
        log(Tag, "ConfirmUpgradeFirmware. UID = " + connectionEntity.getUid());
        long callid = System.currentTimeMillis();
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerConfirmUpgradeFirmwareCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.ConfirmUpgradeFirmware", params, callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    public boolean GetTimeZone(ConnectionEntity connectionEntity, GetTimeZone getTimeZoneCallBack) {
        log(Tag, "GetTimeZone. UID = " + connectionEntity.getUid());
        this.getTimeZoneCallBack = getTimeZoneCallBack;
        long callid = System.currentTimeMillis() / 1000;
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerGetTimeZoneCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.GetTimeZone", "{}", callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    public boolean GetTimeZone(ConnectionEntity connectionEntity, GetTimeZone getTimeZoneCallBack, int delay) {
        log(Tag, "GetTimeZone. UID = " + connectionEntity.getUid());
        this.getTimeZoneCallBack = getTimeZoneCallBack;
        long callid = System.currentTimeMillis() / 1000;
        if (delay != 0) {
            callid = callid + delay;
        }
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerGetTimeZoneCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.GetTimeZone", "{}", callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    public boolean SetTimeZone(ConnectionEntity connectionEntity, String params, SetTimeZone setTimeZoneCallBack) {
        log(Tag, "SetTimeZone. UID = " + connectionEntity.getUid());
        this.setTimeZoneCallBack = setTimeZoneCallBack;
        long callid = System.currentTimeMillis();
        ResponseHandler handler = new ResponseHandler();
        handler.setCallback(mSystemManagerSetTimeZoneCallBack);
        connectionEntity.mReqRspHashMap.put(callid, handler);
        if (!SendCommand(connectionEntity, connectionEntity.getUid(), "SystemManager.SetTimeZone", params, callid)) {
            connectionEntity.mReqRspHashMap.remove(callid);
            return false;
        } else {
            return true;
        }
    }

    public interface onReboot {
        void onRebootCallBack(int ret);
    }

    public interface GetInfoCallBack {
        void onGetInfoResponseCallBack(int ret, String version);
    }

    public interface QueryStorageInfoCallBack {
        void onQueryStorageInfoResponseCallBack(int ret, JSONObject info);
    }

    public interface QueryFlashInfoCallBack {
        void onQueryFlashInfoResponseCallBack(int ret, JSONObject info);
    }

    public interface ResetCallBack {
        void onResetCallBack(int ret, JSONObject info);
    }

    public interface DownloadCallBack {
        void onDownloadCallBack(int ret);
    }

    public interface ConfirmCallBack {
        void onConfirmCallBack(int ret);
    }

    public interface GetTimeZone {
        void onGetTimeZoneCallBack(String result);
    }

    public interface SetTimeZone {
        void onSetTimeZoneCallBack(String result);
    }

    public interface ModifyPassword {
        void onModifyPasswordCallBack(int ret);
    }

    private static class SystemManagerInstance {
        private static final SystemManager instance = new SystemManager();
    }
}
